package com.dl.mall.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author DL
 * @create 2022-3-19 15:23:23
 */
@Component
public class InfoInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //获取请求头中的令牌

        String uri = request.getRequestURI();//获取请求信息
        String queryString = request.getQueryString();//获取请求参数
        String referer = request.getHeader("referer");//请求的来源
        if (queryString == null){
            System.out.println("本次请求由  " + referer + "  ==>  " + uri + "  ");
        }else {
            System.out.println("本次请求由  " + referer + "  ==>  " + uri + "?" + queryString);
        }

        return true;
    }
}
